package youcheng.work.view_zhexian;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

import butterknife.ButterKnife;
import youcheng.work.view_zhexian.utils.BaseActivity;

public class AddActivity extends BaseActivity {

/*  声明控件*/
    private TextView tvTitle;
    private TextView reset;
    private TextView tvConfirm;
    private EditText edcur;

  //  private TextView tv_Value1;
    private TextView tv_Value2;
    private TextView tv_Value3;
  //  private SeekBar  seekBar1;
    private SeekBar  seekBar2;
    private SeekBar  seekBar3;


    private int    Fre;
    private float  Amp;
    private String  Wave;
    private boolean sin = false;
    private boolean squ = false;
    private boolean tri = false;
    private String output;
    private static Handler mHandler = null;
/*
    private String   temp1;
    private String   temp2;
    private String   temp3;
*/
    private ImageView imgv_return;
/*
    EditText edt_1;
    EditText edt_2;
    EditText edt_3;
*/


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        ButterKnife.bind(this);
/*  通过R。id 获取控件  */
        /*  title 标题设置*/
        tvTitle = findViewById(R.id.tv_title);
        tvTitle.setText("控制调节参数");
        /* Current parameters 当前参数*/

        /* ImageView 图片视图*/
        imgv_return = findViewById(R.id.imgv_return);
        /* */
        tvConfirm = findViewById(R.id.tvConfirm);
        edcur=findViewById(R.id.edcur);
        reset=findViewById(R.id.tvreset);


        //////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////

        /* 监听返回键*/
        imgv_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();/*返回上一个activity*/
            }
        });
        reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             clearAppUserData("youcheng.work.view_zhexian");
            }
        });
        //////////////////////////////////////////////////////////
        /* 获取对应的进度条控件seekbar以及 编辑框edittext控件*/

        tv_Value2=findViewById(R.id.tvValue2);
        tv_Value3=findViewById(R.id.tvValue3);


        seekBar2=findViewById(R.id.seekBar2);
        seekBar3=findViewById(R.id.seekBar3);


        seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override//进行
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_Value2.setText("当前数值："+progress*0.033);
                Amp= (float)(progress*0.033);
            }

            @Override//开始
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override//暂停
            public void onStopTrackingTouch(SeekBar seekBar) {
                tv_Value2.setText("最终数值："+Amp);

            }


        });

        seekBar3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override//进行
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_Value3.setText("当前数值："+progress);
                Fre= progress*10;
            }

            @Override//开始
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override//暂停
            public void onStopTrackingTouch(SeekBar seekBar) {
                tv_Value3.setText("最终数值："+Fre);

            }


        });

        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /* 判空操作， 为空则报错 */
                sin =((CheckBox) (findViewById(R.id.sin))).isChecked();
                squ =((CheckBox) (findViewById(R.id.squ))).isChecked();
                tri =((CheckBox) (findViewById(R.id.tri))).isChecked();
                if(sin){
                    Wave="0";
                }
                if(squ){
                    Wave="1";
                }
                if(tri){
                    Wave="2";
                }
                if (Fre==0 || Amp==0 || Wave ==null) {
                    Toast.makeText(AddActivity.this, "数据设置不完整请仔细检查！", Toast.LENGTH_SHORT).show();

                    return;
                }
                else{
                    //Toast.makeText(AddActivity.this, "周期信号幅值为 :"+Amp+"\n" +"周期信号频率:"+Fre, Toast.LENGTH_SHORT).show();
                    output="Aw:"+Wave+"f:"+Fre+"h:"+Amp+"C"+"\n";

                  //  mHandler.obtainMessage(BLEIOActivity.PAINT_SET, -1, -1,  output).sendToTarget();

                    edcur.setText(output);

                }
            }

        });

    }
    //pm clear 包名重置系统数据
    public static Process clearAppUserData(String packageName) {
        Process p = execRuntimeProcess("pm clear " + packageName);
        return p;
    }

    public static  Process execRuntimeProcess(String commond) {
        Process p = null;
        try {
            p = Runtime.getRuntime().exec(commond);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return p;
    }


}
                /* 用bean来存储 获取的temp值


                Bean tempBean = new Bean();
                tempBean.data=StringUtil.getTodayData_3();
                tempBean.value0=(temp1);
                tempBean.value1=(temp2);
                tempBean.value2=(temp3);
                tempBean.save();*/
                /* 判断是否存储成功
                if (tempBean.isSaved()) {

                    Toast toast = Toast.makeText(AddActivity.this, "设置成功", Toast.LENGTH_SHORT);
                    ImageView imageView=new ImageView(getApplicationContext());
                    imageView.setImageResource(R.mipmap.success1);
                    LinearLayout toastView=(LinearLayout) toast.getView();

                    toastView.setOrientation(LinearLayout.VERTICAL);
                    toastView.addView(imageView, 0);
                    toast.show();
                    finish();
                }*/




        /*查询Bean.class里的内容是否为null 为null则显示暂无数据反之显示具体数据

        Bean bean = DataSupport.findLast(Bean.class);//查询表Comment
        if (bean == null) {
            tvcur.setText("暂无数据");
        } else {
            tvcur.setText(
                    "上一次改动时间：" + bean.data + "\n" +
                            "直流信号幅值：" + bean.value0 + "\n" +
                            "周期信号幅值：" + bean.value1 + "\n" +
                            "周期信号频率：" + bean.value2
            );
        }*/
